﻿@model Think9.Models.TbBasicEntity
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<input style="display: none" name="id" id="id">
<input style="display: none" name="FlowId" id="FlowId" value="@Model.FlowId">
<form class="layui-form" lay-filter="formEdit">
    <div class="layui-form-item">
        <label class="layui-form-label">选择分类</label>
        <div class="layui-input-block">
            @Html.DropDownList("TbSortId", (IEnumerable<SelectListItem>)ViewBag.TbSortList, "==请选择分类==", new Dictionary<string, object> { })
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">主表编码</label>
        <div class="layui-input-block">
            <input type="text" name="TbId" id="TbId" placeholder="主表编码" autocomplete="off" class="layui-input" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">主表名称</label>
        <div class="layui-input-block">
            <input type="text" name="TbName" id="TbName" placeholder="主表名称" autocomplete="off" class="layui-input" lay-verify="required" maxlength="30">
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <label class="layui-form-label">录入表类型</label>
            <div class="layui-input-block">
                <input type="hidden" name="BInfo" value="2">
                <span style="position: absolute;bottom: 7px; ">
                    <input type="checkbox" name="BInfo" id="BInfo" lay-skin="primary" title="基本信息表(无需流程及审核 由指定用户录入编辑)" value="1" lay-filter="BInfo" disabled="disabled">
                </span>
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">流程类型</label>
            <div class="layui-input-block">
                <select name="FlowType" id="FlowType" disabled="disabled">
                    <option value="2">自由流程</option>
                    <option value="1">固定流程</option>
                    <option value="0">无流程</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item" id="divEditUser" style="display:none">
        <label class="layui-form-label required">编辑用户</label>
        <div class="layui-input-block">
            <input type="hidden" name="EditUser" id="EditUser">
            <input type="text" name="EditUser_Exa" id="EditUser_Exa" placeholder="选择的用户才能录入编辑数据 点击选择..." autocomplete="off" class="layui-input">
            <span style="position: absolute;bottom: 6px; right: 5px;">
                <a href="javascript:;"><i class="fa fa-check-circle" id="selectEditUser">选择</i></a>
                <a href="javascript:;"><i class="fa fa-check" id="allEditUser">所有</i></a>
            </span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序号</label>
        <div class="layui-input-block">
            <input type="text" name="OrderNo" id="OrderNo" placeholder="排序号" autocomplete="off" class="layui-input" maxlength="3" lay-verify="required|number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备 注</label>
        <div class="layui-input-block">
            <textarea placeholder="" value="" name="TbExplain" id="TbExplain" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="edit">编辑</button>
        </div>
    </div>
</form>

<script>
	layui.use(["table", 'form', "exLayer", "exUtils"], function () {
		let form = layui.form;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let table = layui.table;

		let $ = layui.$;

		getFormVal();

		//给表单赋值
		form.val("formEdit", {
			"TbSortId": "@Model.TbSortId",
			"TbId": "@Model.TbId",
			"TbName": "@Model.TbName",
			"BInfo": "@Model.BInfo",
			"OrderNo": "@Model.OrderNo",
			"FlowType": "@Model.FlowType",
			"TbExplain": "@Model.TbExplain"
		});

		function getFormVal() {
			if (@Model.BInfo == "1") {
				$('#BInfo').attr("checked", true);
				$("#divEditUser").show();
				$("#EditUser_Exa").val('@Model.EditUser_Exa');
			}
			else {
				$("#BInfo").removeAttr("checked");
				$("#divEditUser").hide();
			}
		}

		//所有用户
		$('#allEditUser').on('click', function () {
			$('#EditUser').val("#all#");
			$('#EditUser_Exa').val("所有用户");

		});
		//选择用户
		$('#EditUser_Exa').on('click', function () {
            exLayer.open("选择用户", "/Com/ComSelect/SelectUser?fId=tbedit&sId=" + $("#EditUser").val(), '100%', '100%', '0px', '0px', null, null);
		});
		//选择用户
		$('#selectEditUser').on('click', function () {
            exLayer.open("选择用户", "/Com/ComSelect/SelectUser?fId=tbedit&sId=" + $("#EditUser").val(), '100%', '100%', '0px', '0px', null, null);
		});

		form.on("submit(edit)", function (data) {
            exUtils.ajax("/SysTable/TbBasic/Edit01", "post", { model: data.field, fwid: $("#FlowId").val()}, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
					/*$(window.parent.document).find('#btn_refresh').click();*/
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
			}).fail(function (error) {
				console.log(error);
			});
			return false;
		});
	})
</script>